package entity.role;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

@SuppressWarnings("serial")
@Entity
@Table(name = "resource")
public class MyResource implements Serializable,Comparable<MyResource> {
	private String id;
	private String name;
	private String url;
	private String type;
	private int ordernum = -1;
	private String datasourcename;
	private String opinion;
	private Boolean activite = true;// 当前资源是否可用（true:可用,false:不可用）
	private MyResource parent;// 当前资源父级
	private List<MyResource> childrens = new ArrayList<MyResource>(0);

	public MyResource() {
	}

	@GenericGenerator(name = "generator", strategy = "uuid.hex")
	@Id
	@GeneratedValue(generator = "generator")
	@Column(name = "ID", unique = true, nullable = false, length = 32)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "name", length = 100)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "url", length = 200)
	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	@Column(name = "type", length = 40)
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	@Column(name = "activite")
	public Boolean getActivite() {
		return activite;
	}

	public void setActivite(Boolean activite) {
		this.activite = activite;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "parent_id")
	public MyResource getParent() {
		return parent;
	}

	public void setParent(MyResource parent) {
		this.parent = parent;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "parent")
	public List<MyResource> getChildrens() {
		return childrens;
	}

	public void setChildrens(List<MyResource> childrens) {
		this.childrens = childrens;
	}

	@Column(name = "ordernum")
	public int getOrdernum() {
		return ordernum;
	}

	public void setOrdernum(int ordernum) {
		this.ordernum = ordernum;
	}
	
	
	@Column(name = "datasourcename", length = 40)
	public String getDatasourcename() {
		return datasourcename;
	}

	public void setDatasourcename(String datasourcename) {
		this.datasourcename = datasourcename;
	}
	@Column(name = "opinion", length = 400)
	public String getOpinion() {
		return opinion;
	}

	public void setOpinion(String opinion) {
		this.opinion = opinion;
	}

	@Override
	public int compareTo(MyResource o) {
		// TODO Auto-generated method stub
		int flag = 0;
		if(this.getOrdernum() >= o.getOrdernum()){
			flag = 1;
		}else{
			flag = -1;
		}
		return flag;
	}

}
